package com.equipment.user.web.api;

import com.baomidou.mybatisplus.plugins.Page;
import com.equipment.user.entity.User;
import com.equipment.user.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ${DESCRIPTION}
 *
 * @author 杨凯
 * @create 2018-04-08 15:23
 **/
@RestController
public class UserController {

	private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);

	@Autowired
	private UserService userService;

	@GetMapping("/users")
	public Map<String, Object> userList(@RequestParam(defaultValue = "0") int start, @RequestParam(defaultValue = "10") int length) {
		Map<String, Object> map = new HashMap<>(3);
		Page page = new Page(start, length);
		Page<User> userPage = userService.selectPage(page);
		List<User> list = userPage.getRecords();
		map.put("data", list);
		map.put("count", userPage.getTotal());
		return map;
	}
}
